import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-02-08
 * Time: 21:15
 */
class Solution8 {
    public int subarraySum(int[] nums, int k) {
        Map<Integer,Integer> map = new HashMap<>();
        map.put(0,1);
        int tmp = 0 , result = 0;
        for(int i = 0 ; i < nums.length ; i++){
            tmp += nums[i];
            int target = tmp - k;
            if(map.containsKey(target)){
                result += map.get(target);
                map.put(tmp,map.getOrDefault(tmp,0)+1);
            }else{
                map.put(tmp,map.getOrDefault(tmp,0)+1);
            }
        }
        return result;
    }
}
public class Test8 {
}
